using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using bitzhuwei.Compiler;

namespace bitzhuwei.AnsiCFormat {
    /// <summary>
    /// Correspond to the Vn node initializer in the grammar(AnsiC).
    /// </summary>
    internal abstract partial class Vninitializer : IFullFormatter {
        public abstract TokenRange Scope { get; }

        public abstract void Format(TextWriter writer, FormatContext context);
        public abstract void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context);
        public abstract IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context);

        // [167]=initializer : assignment_expression ;
        // [168]=initializer : '{' initializer_list '}' ;
        // [169]=initializer : '{' initializer_list ',' '}' ;

        public class assign_ : Vninitializer {

            // [167]=initializer : assignment_expression ;
            // dumped by DefaultExtractor
            internal assign_(Vnassignment_expression r0) {
                this.r0 = r0;
                this._scope = new TokenRange(r0);
            }
            private readonly Vnassignment_expression r0;
            private readonly TokenRange _scope;

            public override TokenRange Scope => _scope;

            public override void Format(TextWriter writer, FormatContext context) {
                throw new NotImplementedException();
            }

            public override void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
                context.PrintBlanksAnd(r0, preConfig, writer);
            }

            public override IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
                throw new NotImplementedException();
            }
        }
        public class list_ : Vninitializer {

            // [168]=initializer : '{' initializer_list '}' ;
            // [169]=initializer : '{' initializer_list ',' '}' ;
            internal list_(Token r3, Vninitializer_list r2, Token? r1, Token r0) {
                this.r3 = r3;
                this.r2 = r2;
                this.r1 = r1;
                this.r0 = r0;
                this._scope = new TokenRange(r3, r0);
            }
            private readonly Token r3;
            private readonly Vninitializer_list r2;
            private readonly Token? r1;
            private readonly Token r0;

            private readonly TokenRange _scope;
            public override TokenRange Scope => _scope;

            public override void Format(TextWriter writer, FormatContext context) {
                throw new NotImplementedException();
            }

            public override void FullFormat(BlankConfig preConfig, TextWriter writer, FormatContext context) {
                context.PrintBlanksAnd(r3, preConfig, writer);
                var config = new BlankConfig(1, r0.start.line > r3.start.line);
                context.PrintCommentsBetween(r3, r2, config, writer);
                context.PrintBlanksAnd(r2, config, writer);
                if (r1 != null) {
                    context.PrintCommentsBetween(r2, r1, config, writer);
                    context.PrintBlanksAnd(r1, config, writer);
                }
                if (r1 != null) { context.PrintCommentsBetween(r1, r0, config, writer); }
                else { context.PrintCommentsBetween(r2, r0, config, writer); }
                context.PrintBlanksAnd(r0, config, writer);
            }

            public override IEnumerable<string> YieldTokens(TextWriter writer, FormatContext context) {
                throw new NotImplementedException();
            }
        }

    }
}
